package com.xyd.servlet;

import com.xyd.entity.Order;
import com.xyd.service.impl.OrderServiceImpl;
import com.xyd.util.JsonUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/OrderGetByIdNameServlet")
public class OrderGetByIdNameServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name=new String(request.getParameter("name").getBytes("UTF-8"));
        System.out.println(name);
        Order order = new Order();
        long id;
        String x=request.getParameter("id");
        if(x!=null&&x!=""){
            id=Long.parseLong(x);
            order.setEoId(id);
        }
        OrderServiceImpl orderService = new OrderServiceImpl();
        order.setEoUsername(name);
        List<Order> list=orderService.getOrderByIdName(order);
        System.out.println(list);
        JsonUtil.toJson(response,list);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
